<!DOCTYPE html>
<html>
<head>
<title>Electromagnetic Induction Diagram</title>
<style>
  body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    background-color: #f0f0f0;
  }
  canvas {
    background-color: white;
    border: 1px solid #d3d3d3;
  }
</style>
</head>
<body>

<canvas id="physics-diagram" width="500" height="420"></canvas>

<script>
  const canvas = document.getElementById('physics-diagram');
  const ctx = canvas.getContext('2d');

  // --- Style and Parameter setup ---
  const centerX = canvas.width / 2;
  const coilWidth = 180;
  const coilHeight = 90;
  const coilX = centerX - coilWidth / 2;
  const coilTopY = 100;
  const coilBottomY = coilTopY + coilHeight;
  const fieldBoundaryY = 170; // Position the coil to be entering the field

  // Clear canvas with white background
  ctx.fillStyle = 'white';
  ctx.fillRect(0, 0, canvas.width, canvas.height);
  ctx.fillStyle = 'black';
  ctx.strokeStyle = 'black';
  ctx.lineWidth = 2.5; // Thicker lines like the original hand-drawn style

  // Helper function to draw 'x' marks for the magnetic field
  function drawX(x, y, size) {
    ctx.save();
    ctx.lineWidth = 2;
    ctx.beginPath();
    ctx.moveTo(x - size, y - size);
    ctx.lineTo(x + size, y + size);
    ctx.moveTo(x + size, y - size);
    ctx.lineTo(x - size, y + size);
    ctx.stroke();
    ctx.restore();
  }

  // 1. Draw the Magnetic Field Region
  // Dashed line for the boundary
  ctx.save();
  ctx.lineWidth = 2;
  ctx.beginPath();
  ctx.setLineDash([12, 8]);
  ctx.moveTo(30, fieldBoundaryY);
  ctx.lineTo(canvas.width - 30, fieldBoundaryY);
  ctx.stroke();
  ctx.restore();

  // 'x' symbols for the field
  const xSize = 5;
  const xSpacing = 40;
  const ySpacing = 35;
  for (let y = fieldBoundaryY + 25; y < fieldBoundaryY + 120; y += ySpacing) {
    for (let x = 45; x < canvas.width - 45; x += xSpacing) {
      drawX(x, y, xSize);
    }
  }

  // Label for the magnetic field
  ctx.font = 'bold 22px serif';
  ctx.fillText('B', canvas.width - 60, fieldBoundaryY + 60);

  // 2. Draw the Rectangular Coil
  ctx.strokeRect(coilX, coilTopY, coilWidth, coilHeight);

  // 3. Draw the Dimension Lines and Labels
  ctx.font = 'italic 22px serif';
  ctx.lineWidth = 1.5;

  // Dimension 'b' (width)
  const dimB_Y = coilTopY - 25;
  ctx.beginPath();
  ctx.moveTo(coilX, dimB_Y);
  ctx.lineTo(coilX + coilWidth, dimB_Y);
  ctx.moveTo(coilX, dimB_Y - 5);
  ctx.lineTo(coilX, dimB_Y + 5);
  ctx.moveTo(coilX + coilWidth, dimB_Y - 5);
  ctx.lineTo(coilX + coilWidth, dimB_Y + 5);
  ctx.stroke();
  ctx.fillText('b', centerX - 5, dimB_Y - 8);

  // Dimension 'a' (height)
  const dimA_X = coilX + coilWidth + 25;
  ctx.beginPath();
  ctx.moveTo(dimA_X, coilTopY);
  ctx.lineTo(dimA_X, coilBottomY);
  ctx.moveTo(dimA_X - 5, coilTopY);
  ctx.lineTo(dimA_X + 5, coilTopY);
  ctx.moveTo(dimA_X - 5, coilBottomY);
  ctx.lineTo(dimA_X + 5, coilBottomY);
  ctx.stroke();
  ctx.fillText('a', dimA_X + 10, coilTopY + coilHeight / 2 + 8);

  // 4. Draw the Velocity Arrow
  ctx.lineWidth = 2;
  const arrowStartX = centerX;
  const arrowStartY = coilBottomY;
  const arrowTipY = arrowStartY + 45;
  const controlPointX = arrowStartX + 10;
  const controlPointY = arrowStartY + 22;

  ctx.beginPath();
  ctx.moveTo(arrowStartX, arrowStartY);
  // Using quadratic curve to replicate the slight curve in the original
  ctx.quadraticCurveTo(controlPointX, controlPointY, arrowStartX + 2, arrowTipY);
  ctx.stroke();

  // Draw the v-shaped arrowhead at the end of the curved line
  // This is a specific feature from the original image
  const vHeadX = arrowStartX + 2;
  const vHeadY = arrowTipY;
  ctx.beginPath();
  ctx.moveTo(vHeadX - 7, vHeadY - 9);
  ctx.lineTo(vHeadX, vHeadY);
  ctx.lineTo(vHeadX + 7, vHeadY - 9);
  ctx.stroke();

  // 5. Draw the Figure Caption
  ctx.fillStyle = 'black';
  ctx.font = 'bold 22px sans-serif';
  ctx.textAlign = 'center';
  ctx.fillText('Fig. 2.36', centerX, canvas.height - 30);

</script>

</body>
</html>